<?php
	session_start();
	
	require('../Scripts/Mapa/php/security/authenticate.php');
	
	
	if (!isset($_SESSION['signature']) || $_SESSION['signature'] == '')
	{
		header ("Location: ../Scripts/Mapa/php/security/403forbidden.php");
		exit();
	}
	
	$link = pg_connect("user=".$_SESSION['usuario']." port=".DB_PORT." dbname=".DB_NAME." host=".DB_HOST." password=".$_SESSION['pass']);
	
	if (!isset($_GET['torre'])) echo "";
	else 
	{
		$torre = $_GET['torre'];
		$_SESSION['torre_upload'] = $torre;
		
		if (!isset($_SESSION['idtorre_upload']) 
			|| $_SESSION['idtorre_upload'] == ''
			|| ($_GET['idtorre'] !== '' &&  $_SESSION['idtorre_upload'] !== $_GET['idtorre']))
		{
			$_SESSION['idtorre_upload'] = $_GET['idtorre'];
		}
	}
	$root = "datos/$torre";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
	<meta http-equiv="content-type" content="type=text/html; charset=ISO-5589-1" />
	<title>Subir y Descargar Archivos</title>
	<script type="text/javascript" src="fmanager/jquery.min.js"></script>
	<script type="text/javascript" src="fmanager/init.js"></script>
	<link rel="stylesheet" type="text/css" href="fmanager/fmanager.css" />
	<link href="fmanager/style.css" rel="stylesheet" type="text/css">

	<script src="fmanager/jquerypp.custom.js"></script>
	<script src="fmanager/framewarp.js"></script>
	<script src="fmanager/script.js"></script>

	<link rel="stylesheet" href="fmanager/framewarp.css" />
</head>
<body>
	<div class="contwindow" style="position:relative; float:center; height:400px;">
	<h2 id="contwindow">ADMINISTRACION DE ARCHIVOS DE LA TORRE: <?php echo $_SESSION['idtorre_upload']; ?></h2>
	<div align="center">
<?php
	session_start();
	
	if (isset($_GET['a'])) $a = $_GET['a']; // accion
	if (isset($_GET['e'])) $e = $_GET['e']; // setting
	if (isset($_GET['do']))$do = $_GET['do']; // sub-level accion
	if (isset($_GET['do']))$id = $_GET['id']; // sub-level objectivo

	$agent = $_SERVER['HTTP_USER_AGENT']; 
	$ip = $_SERVER['REMOTE_ADDR']; 
	$ts = $_SERVER['REQUEST_TIME']; 
	$self = $_SERVER['PHP_SELF']; 
	$key = md5($agent.$ip.$ts.$self); 
	$uri = addslashes($_SERVER['REQUEST_URI']); 
	$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	$host = $_SERVER['HTTP_HOST']; 
	$domain = str_replace(array("www.", "cms.", "cpp."), "", $host); 
	$max_upload = (int)( ini_get('upload_max_filesize') );
	$max_post   = (int)( ini_get('post_max_size') );
	$max_memory = (int)( ini_get('memory_limit') );
	$upload_max = min($max_upload, $max_post, $max_memory);

	function file_byte($a_bytes)
	{
		if ($a_bytes < 1024) {
			return $a_bytes .' B';
		} elseif ($a_bytes < 1048576) {
			return round($a_bytes / 1024, 0) .' KB';
		} elseif ($a_bytes < 1073741824) {
			return round($a_bytes / 1048576, 1) . ' MB';
		} elseif ($a_bytes < 1099511627776) {
			return round($a_bytes / 1073741824, 2) . ' GB';
		} elseif ($a_bytes < 1125899906842624) {
			return round($a_bytes / 1099511627776, 2) .' TB';
		} elseif ($a_bytes < 1152921504606846976) {
			 return round($a_bytes / 1125899906842624, 2) .' PB';
		} elseif ($a_bytes < 1180591620717411303424) {
			 return round($a_bytes / 1152921504606846976, 2) .' EB';
		} elseif ($a_bytes < 1208925819614629174706176) {
			 return round($a_bytes / 1180591620717411303424, 2) .' ZB';
		} else {
			 return round($a_bytes / 1208925819614629174706176, 2) .' YB';
		}
	}

	function dirsize($directory) {
	   $size = 0;
	   foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file){
		  $size+=$file->getSize();
	   }
	   return $size;
	}

	function filename_safe($name) {
		$except = array('#', '=', '!', '\\', '/', ':', ';', '*', '?', '"', '<', '>', '|', '{', '}', '%', '¤', '\'', '(', ')', '$', '£', '´', '`', '~', '¨', '^', ',', '&');
		return str_replace($except, '', $name); 
	} 

	function remdir($dir) {
	   if (is_dir($dir)) {
		  $objects = scandir($dir);
		  foreach ($objects as $object) {
			 if ($object != "." && $object != "..") {
				if (filetype($dir."/".$object) == "dir") remdir($dir."/".$object); else unlink($dir."/".$object);
			 }
		  }
		  reset($objects);
		  rmdir($dir);
	   }
	}

	if(isset($_GET['type'])) $type = $_GET['type'];
	if(isset($_GET['type']) && $type == "1") { $type = "dir"; } else { $type = "file"; }

	$dir = $_GET['dir'];
	
	$dir = $dir;
	
	if($dir==null 
		|| $dir=="." 
		|| $dir=="/" 
		|| $dir=="./" 
		|| $dir[0]=="/" 
		|| substr($dir, -2) == ".." 
		|| substr($dir, -2) == "./" 
		|| substr($dir, -2) == "//" 
		|| substr($dir, -1) == "." ) 
	{ 
		$dir = $root; 
	}
	if(substr($dir, 0, strlen($root)) != $root) { $dir = $root.$dir; }
	$path = $dir;

	$folder = explode('/', $path, -1);
	$count = count(explode('/', $path, -1));
	$count = $count-1;

	if(isset($_GET['uri'])) $uri = $_GET['uri'];
	$uri_path = explode('/', $uri, -1);
	$uri_count = count(explode('/', $uri, -1));
	$uri_count = $uri_count-1;

	$css_row = 0;

	$title = $path;
	if($count >= 2)
	{
		$title = $folder[0].'/';
		$slashes = $count - 1;
		while($slashes>0)
		{
			$title .= '../';
			$slashes--;
		}
	   $title .= $folder[$count];
	   $title .= '/';
	}

	$strip_last = strlen($folder[$count]) + 1;
	$up = substr($path, 0, -$strip_last);


	if(isset($_GET['a']) && $a == "freply")
	{
		echo '<div id="h2"><span style="color:#bbb;"> reply ';
		if($type == "dir") { echo "folder"; } else { echo "to"; }
		echo '</span> '.$uri_path[$uri_count].'</div>'."\n";
		echo '<br />'."\n";
		echo '<div style="width:600px;height:24px;border-bottom:1px solid #eee;" align="left">'."\n";
		echo '   <div style="width:300px;float:left;">'."\n";
		echo '   <table align="left" cellspacing="0" cellpadding="0"><tr>'."\n";
		echo '   <td align="left" valign="middle"><span class="f_icon"><img src="fmanager/';
		if($type == "dir") { echo "folder.png"; } else { echo "file.png"; }
		echo '" height="20" width="20" border="0" /></span></td>'."\n";
		echo '   <td align="left" valign="top"><span class="f_file" style="color:#777;font-weight:bold;">freply ';
		if($type == "dir") { echo "folder"; } else { echo "file"; }
		echo '   </span></td>'."\n";
		echo '   </tr></table>'."\n";
		echo '   </div>'."\n";
		echo '   <div style="width:300px;float:right;">'."\n";
		echo '   <table align="right" cellspacing="0" cellpadding="0"><tr>'."\n";
		echo '   <td align="right" valign="middle"><a href="fmanager.php?dir='.$dir.'" class="f_icon" style="margin:0 0 0 15px;"><img src="fmanager/edit_undo.png" height="20" width="20" border="0" /></a></td>'."\n";
		echo '   <td align="right" valign="top"><a href="fmanager.php?dir='.$dir.'" class="f_file" style="color:#333;">Cancelar</a></td>'."\n";
		echo '   </tr></table>'."\n";
		echo '   </div>'."\n";
		echo '</div>'."\n";
		echo '<div style="width:600px;height:80px;background:#f9f9f9;border-bottom:1px solid #eee;" align="left">'."\n";
		echo '   <form action="fmanager.php?exec=rename&dir='.$dir.'&uri='.substr($uri, 0, -1).'" method="post">'."\n";
		echo '   <div style="width:600px;" align="center">'."\n";
		echo '   <table align="center" height="80" cellspacing="0" cellpadding="0"><tr>'."\n";
		echo '   <td valign="middle"><img src="fmanager/';
		if($type == "dir") { echo "folder.png"; } else { echo "file.png"; }
		echo '" height="32" width="32" border="0" /></td>'."\n";
		echo '   <td valign="middle">&nbsp;<input type="text" class="input" style="font-size:14px;" value="'.$uri_path[$uri_count].'" name="rename" /></td>'."\n";
		echo '   <td valign="middle"><input type="hidden" name="submitted" value="true" /><input type="submit" class="submit" value=" Rename " name="exec" /></td>'."\n";
		echo '   </tr></table>'."\n";
		echo '   </div>'."\n";
		echo '   </form>'."\n";
		echo '</div>'."\n";
	} 
	elseif(isset($_GET['a']) && $a == "rename")
	{
		echo '<div id="h2"><span style="color:#bbb;">Cambiar nombre ';
		if($type == "dir") { echo "carpeta"; } else { echo "file"; }
		echo '</span> '.$uri_path[$uri_count].'</div>'."\n";
		echo '<br />'."\n";
		echo '<div style="width:600px;height:24px;border-bottom:1px solid #eee;" align="left">'."\n";
		echo '   <div style="width:300px;float:left;">'."\n";
		echo '   <table align="left" cellspacing="0" cellpadding="0"><tr>'."\n";
		echo '   <td align="left" valign="middle"><span class="f_icon"><img src="fmanager/';
		if($type == "dir") { echo "folder.png"; } else { echo "file.png"; }
		echo '" height="20" width="20" border="0" /></span></td>'."\n";
		echo '   <td align="left" valign="top"><span class="f_file" style="color:#777;font-weight:bold;">Cambiar nombre ';
		if($type == "dir") { echo ""; } else { echo ""; }
		echo '   </span></td>'."\n";
		echo '   </tr></table>'."\n";
		echo '   </div>'."\n";
		echo '   <div style="width:300px;float:right;">'."\n";
		echo '   <table align="right" cellspacing="0" cellpadding="0"><tr>'."\n";
		echo '   <td align="right" valign="middle"><a href="fmanager.php?dir='.$dir.'" class="f_icon" style="margin:0 0 0 15px;"><img src="fmanager/edit_undo.png" height="20" width="20" border="0" /></a></td>'."\n";
		echo '   <td align="right" valign="top"><a href="fmanager.php?dir='.$dir.'" class="f_file" style="color:#333;">Cancelar</a></td>'."\n";
		echo '   </tr></table>'."\n";
		echo '   </div>'."\n";
		echo '</div>'."\n";
		echo '<div style="width:600px;height:80px;background:#f9f9f9;border-bottom:1px solid #eee;" align="left">'."\n";
		echo '   <form action="fmanager.php?exec=rename&dir='.$dir.'&uri='.substr($uri, 0, -1).'" method="post">'."\n";
		echo '   <div style="width:600px;" align="center">'."\n";
		echo '   <table align="center" height="80" cellspacing="0" cellpadding="0"><tr>'."\n";
		echo '   <td valign="middle"><img src="fmanager/';
		if($type == "dir") { echo "folder.png"; } else { echo "file.png"; }
		echo '" height="32" width="32" border="0" /></td>'."\n";
		echo '   <td valign="middle">&nbsp;<input type="text" class="input" style="font-size:14px;" value="'.$uri_path[$uri_count].'" name="rename" /></td>'."\n";
		echo '   <td valign="middle"><input type="submit" class="submit" value=" Cambiar " name="exec" /></td>'."\n";
		echo '   </tr></table>'."\n";
		echo '   </div>'."\n";
		echo '   </form>'."\n";
		echo '</div>'."\n";
	}
	elseif(isset($_GET['a']) && $a == "upload"){
		echo '<div id="h2"><span style="color:#bbb;">Subir archivo en</span> '.$title.'</div>'."\n";
		echo '<br />'."\n";
		echo '<div style="width:600px;height:24px;border-bottom:1px solid #eee;" align="left">'."\n";
		echo '   <div style="width:300px;float:left;">'."\n";
		echo '   <table align="left" cellspacing="0" cellpadding="0"><tr>'."\n";
		echo '   <td align="left" valign="middle"><span class="f_icon"><img src="fmanager/document_new.png" height="20" width="20" border="0" /></span></td>'."\n";
		echo '   <td align="left" valign="top"><span class="f_file" style="color:#777;font-weight:bold;">Subir archivo</span></td>'."\n";
		echo '   </tr></table>'."\n";
		echo '   </div>'."\n";
		echo '   <div style="width:300px;float:right;">'."\n";
		echo '   <table align="right" cellspacing="0" cellpadding="0"><tr>'."\n";
		echo '   <td align="right" valign="middle"><a href="fmanager.php?dir='.$dir.'" class="f_icon" style="margin:0 0 0 15px;"><img src="fmanager/edit_undo.png" height="20" width="20" border="0" /></a></td>'."\n";
		echo '   <td align="right" valign="top"><a href="fmanager.php?dir='.$dir.'" class="f_file" style="color:#333;">Cancelar</a></td>'."\n";
		echo '   </tr></table>'."\n";
		echo '   </div>'."\n";
		echo '</div>'."\n";
		echo '<div style="width:600px;height:100px;background:#f9f9f9;border-bottom:1px solid #eee;" align="left">'."\n";
		echo '   <form action="fmanager.php?exec=upload&dir='.$dir.'" method="post" enctype="multipart/form-data">'."\n";
		echo '   <div style="width:600px;" align="center">'."\n";
		echo '   <table align="center" height="100" cellspacing="0" cellpadding="0"><tr>'."\n";
		echo '   <td valign="middle"><img src="fmanager/document_new.png" height="32" width="32" border="0" /></td>'."\n";
		echo '   <td valign="middle">&nbsp;<input type="file" class="input" style="height:24px;" name="upload" /></td>'."\n";
		echo '   <td valign="middle"><input type="submit" class="submit" value=" Subir " name="exec" /></td>'."\n";
		echo '   </tr><td colspan="3" height="20" valign="top" align="center"><div align="center" style="font-size:11px;">Tamaño maximo: <b>'.$upload_max.'MB</b>!</div></td>';
		echo '   </tr></table>'."\n";
		echo '   </div>'."\n";
		echo '   </form>'."\n";
		echo '</div>'."\n";
	} 
	elseif(isset($_GET['a']) && $a == "mkdir")
	{
		echo '<div id="h2"><span style="color:#bbb;">Nueva carpeta in</span> '.$title.'</div>'."\n";
		echo '<br />'."\n";
		echo '<div style="width:600px;height:24px;border-bottom:1px solid #eee;" align="left">'."\n";
		echo '   <div style="width:300px;float:left;">'."\n";
		echo '   <table align="left" cellspacing="0" cellpadding="0"><tr>'."\n";
		/*echo '   <td align="left" valign="middle"><span class="f_icon"><img src="fmanager/folder_new.png" height="20" width="20" border="0" /></span></td>'."\n";*/
		echo '   <td align="left" valign="top"><span class="f_file" style="color:#777;font-weight:bold;">Nueva carpeta</span></td>'."\n";
		echo '   </tr></table>'."\n";
		echo '   </div>'."\n";
		echo '   <div style="width:300px;float:right;">'."\n";
		echo '   <table align="right" cellspacing="0" cellpadding="0"><tr>'."\n";
		echo '   <td align="right" valign="middle"><a href="fmanager.php?dir='.$dir.'" class="f_icon" style="margin:0 0 0 15px;"><img src="fmanager/edit_undo.png" height="20" width="20" border="0" /></a></td>'."\n";
		echo '   <td align="right" valign="top"><a href="fmanager.php?dir='.$dir.'" class="f_file" style="color:#333;">Cancelar</a></td>'."\n";
		echo '   </tr></table>'."\n";
		echo '   </div>'."\n";
		echo '</div>'."\n";
		echo '<div style="width:600px;height:80px;background:#f9f9f9;border-bottom:1px solid #eee;" align="left">'."\n";
		echo '   <form action="fmanager.php?exec=mkdir&dir='.$dir.'" method="post">'."\n";
		echo '   <div style="width:600px;" align="center">'."\n";
		echo '   <table align="center" height="80" cellspacing="0" cellpadding="0"><tr>'."\n";
		echo '   <td valign="middle"><img src="fmanager/folder_new.png" height="32" width="32" border="0" /></td>'."\n";
		echo '   <td valign="middle">&nbsp;<input type="text" class="input" style="font-size:14px;" value="" name="mkdir" /></td>'."\n";
		echo '   <td valign="middle"><input type="submit" class="submit" value=" Guardar " name="exec" /></td>'."\n";
		echo '   </tr></table>'."\n";
		echo '   </div>'."\n";
		echo '   </form>'."\n";
		echo '</div>'."\n";
	} 
	else 
	{
		if(isset($_GET['exec'])) 
		{
			$exec = $_GET['exec'];

			if($exec == "mkdir")
			{
				if(($_POST['mkdir']))
				{
					mkdir($dir.filename_safe($_POST['mkdir']));
				}
			}

			if($exec == "unlink")
			{
				if($type == "dir")
				{
					remdir($uri);
				}
				elseif($type == "file")
				{
					unlink($uri);
				}
				
				$dirr = opendir($dir);
				$filecount = 0;
				while (false !== ($file = readdir($dirr)))
				{
					if (!in_array($file, array('.', '..')) and !is_dir($file)) $filecount++;
				}
				
				
				if ($filecount == 0)
					pg_query("select * from sp_elimina_archivo_torre('".$_SESSION['torre_upload']."')");
			}

			if($exec == "rename")
			{
				rename($uri, $dir.'/'.filename_safe($_POST['rename']));
			}

			if($exec == "upload")
			{
				if(file_exists($_FILES['upload']['tmp_name'])) 
				{
					move_uploaded_file($_FILES['upload']['tmp_name'], $dir.'/'.filename_safe($_FILES['upload']['name']));
					//Marcamos que tiene archivo adjunto asociado la torre en cuestión
					pg_query("select * from sp_adjunta_archivo_torre('".$_SESSION['torre_upload']."')");
				}
			}
		}

		if($dir!=null && $dir!=$root)
		{
			echo '<div id="h2"><span style="color:#bbb;">Carpeta</span> '.$title.'</div>'."\n";
			echo '<table class="f_row" style="width:600px;" cellspacing="0" cellpadding="0">'."\n";
			echo '<tr>'."\n";
			echo '<td style="border-bottom:1px solid #eee;" colspan="6" align="left" valign="bottom">'."\n";
			echo '   <div style="float:left;width:250px;"><table align="left" cellspacing="0" cellpadding="0"><tr>'."\n";
			echo '      <td class="f_row_td1" align="left" valign="middle"><span class="f_icon"><img src="fmanager/folder.png" height="20" width="20" border="0" /></span></td>'."\n";
			echo '      <td class="f_row_td2" align="left" valign="top"><span class="f_file" style="color:#5E98E1;font-weight:bold;">'.substr($folder[$count], 0, 25).'</span></td>'."\n";
			echo '   </tr></table></div>'."\n";
			echo '   <div style="float:right;width:400px;"><table align="right" cellspacing="0" cellpadding="0"><tr>'."\n";
			/*
			echo '      <td valign="middle"><table cellspacing="0" cellpadding="0"><tr><td valign="middle">
			<a class="f_icon" style="margin:0 0 0 15px;" href="fmanager.php?dir='.$up.'">
				<img src="fmanager/go_up.png" height="20" width="20" border="0" />
			</a>
			</td>
			<td valign="top">
			<a class="f_file" style="color:#333;" href="fmanager.php?dir='.$up.'">Up</a></td></tr></table></td>'."\n";
			
			
			echo '      <td valign="middle"><table cellspacing="0" cellpadding="0"><tr><td valign="middle"><a class="f_icon" style="margin:0 0 0 15px;" href="fmanager.php?dir='.$root.'"><img src="fmanager/folder_home.png" height="20" width="20" border="0" /></a></td><td valign="top"><a class="f_file" style="color:#333;" href="fmanager.php?dir='.$root.'">Root</a></td></tr></table></td>'."\n";
			*/
			
			echo '      <td valign="middle"><table cellspacing="0" cellpadding="0"><tr><td valign="middle"><a class="f_icon" style="margin:0 0 0 15px;" href="fmanager.php?a=upload&dir='.$path.'"><img src="fmanager/document_new.png" height="20" width="20" border="0" /></a></td><td valign="top"><a class="f_file" style="color:#333;" href="fmanager.php?a=upload&dir='.$path.'">Subir archivo</a></td></tr></table></td>'."\n";
			/*echo '      <td valign="middle"><table cellspacing="0" cellpadding="0"><tr><td valign="middle"><a class="f_icon" style="margin:0 0 0 15px;" href="fmanager.php?a=mkdir&dir='.$path.'"><img src="fmanager/folder_new.png" height="20" width="20" border="0" /></a></td><td valign="top"><a class="f_file" style="color:#333;" href="fmanager.php?a=mkdir&dir='.$path.'">Nueva carpeta</a></td></tr></table></td>'."\n";*/
			echo '   </tr></table></div>'."\n";
			echo '</td>'."\n";
			echo '</tr>'."\n";
		} else 
		{
			echo '<div id="h2"><span style="color:#bbb;">Carpeta </span> '.$title.'</div>'."\n";
			echo '<table class="f_row" style="width:600px;" cellspacing="0" cellpadding="0">'."\n";
			echo '<tr>'."\n";
			echo '<td style="border-bottom:1px solid #eee;" colspan="6" align="left" valign="bottom">'."\n";
			echo '   <div style="float:left;width:250px;"><table align="left" cellspacing="0" cellpadding="0"><tr>'."\n";
			echo '      <td class="f_row_td1" align="left" valign="middle"><span class="f_icon"><img src="fmanager/folder_home.png" height="20" width="20" border="0" /></span></td>'."\n";
			echo '      <td class="f_row_td2" align="left" valign="top"><span class="f_file" style="color:#5E98E1;font-weight:bold;">Root</span></td>'."\n";
			echo '   </tr></table></div>'."\n";
			echo '   <div style="float:right;width:400px;"><table align="right" cellspacing="0" cellpadding="0"><tr>'."\n";
			echo '      <td valign="middle"><table cellspacing="0" cellpadding="0"><tr><td valign="middle"><a class="f_icon" style="margin:0 0 0 15px;" href="fmanager.php?a=upload&dir='.$path.'"><img src="fmanager/document_new.png" height="20" width="20" border="0" /></a></td><td valign="top"><a class="f_file" style="color:#333;" href="fmanager.php?a=upload&dir='.$path.'">Subir archivo</a></td></tr></table></td>'."\n";
			/*echo '      <td valign="middle"><table cellspacing="0" cellpadding="0"><tr><td valign="middle"><a class="f_icon" style="margin:0 0 0 15px;" href="fmanager.php?a=mkdir&dir='.$path.'"><img src="fmanager/folder_new.png" height="20" width="20" border="0" /></a></td><td valign="top"><a class="f_file" style="color:#333;" href="fmanager.php?a=mkdir&dir='.$path.'">Nueva carpeta</a></td></tr></table></td>'."\n";*/
			echo '   </tr></table></div>'."\n";
			echo '</td>'."\n";
			echo '</tr>'."\n";
		}

		$folder = array();
		$dir_handle = @opendir($dir) or die("No se puede abrir $path");
		$i = 0;
		while($foldername = readdir($dir_handle)) 
		{ 
			if($foldername != '.' 
				&& $foldername != '..' 
				&& $foldername != 'fmanager' 
				&& is_dir($dir.$foldername) == true) 
			{ 
				$folder[$i] = $foldername; $i++; 
			} 
		}
		array_multisort(array_map('strtolower', $folder), $folder);
		for($i=0; $i<sizeof($folder); $i++)
		{
			$ext = substr(strrchr($folder[$i], '.'), 1);
			$css_row++;
			echo '<tr class="f_row_s'.($css_row & 1).'">'."\n";
			echo '   <td class="f_row_td1" align="left" valign="middle" style="padding-top:1px;"><a class="f_icon" href="fmanager.php?dir='.$path.'/'.$folder[$i].'/"><img src="fmanager/folder.png" height="20" width="20" border="0" /></a></td>'."\n";
			echo '   <td class="f_row_td2" align="left" valign="top" style=""><a class="f_file" style="color:#333;" href="fmanager.php?dir='.$path.'/'.$folder[$i].'/">'.substr($folder[$i], 0, 70).'</a></td>'."\n";
			echo '   <td class="f_row_td3" align="left" valign="top" style="padding-top:1px;text-align:right;"><a class="f_file" style="color:#333;" href="fmanager.php?dir='.$path.'/'.$folder[$i].'/">'.file_byte(dirsize($path.'/'.$folder[$i])).'</a></td>'."\n";
			echo '   <td class="f_row_td4" align="left" valign="top" style="padding-top:1px;text-align:right;"><a class="f_file" style="color:#333;" href="fmanager.php?dir='.$path.'/'.$folder[$i].'/">'.date("d.m.Y H:i", filemtime($path.'/'.$folder[$i])).'</a></td>'."\n";
			echo '   <td class="f_row_td5" align="left" valign="middle" style="padding-top:1px;text-align:right;"><a class="f_icon" href="fmanager.php?a=rename&type=1&dir='.$dir.'&uri='.$path.'/'.$folder[$i].'/" title="Cambiar nombre "><img src="fmanager/edit_rename.png" width="18" height="18" border="0" /></a></td>'."\n";
			echo '   <td class="f_row_td6" align="left" valign="middle" style="padding-top:1px;text-align:right;"><a class="f_icon" href="fmanager.php?exec=unlink&type=1&dir='.$dir.'&uri='.$path.'/'.$folder[$i].'/" title="Eliminar carpeta"><img src="fmanager/edit_delete.png" width="16" height="16" border="0" /></a></td>'."\n";
			echo '</tr>'."\n";
		}
		closedir($dir_handle);
		$file = array();
		$dir_handle = @opendir($dir) or die("No c puede abrir $path");
		$i = 0;
		while($filename = readdir($dir_handle)) { if($filename != '.' && $filename != '..' && $filename != 'fmanager.php' && is_dir($dir.$filename) != true) { $file[$i] = $filename; $i++; } }
		array_multisort(array_map('strtolower', $file), $file);
		for($i=0; $i<sizeof($file); $i++)
		{
			$ext = substr(strrchr($file[$i], '.'), 1);
			$css_row++;
			echo '<tr class="f_row_s'.($css_row & 1).'">'."\n";
			echo '   <td class="f_row_td1" align="left" valign="middle"><a class="f_icon" href="'.$path.'/'.$file[$i].'" target="_BLANK"><img src="fmanager/'.strtolower($ext).'.png" height="20" width="20" border="0" /></a></td>'."\n";
			echo '   <td class="f_row_td2" align="left" valign="top" style="padding-top:1px;"><a class="f_file" style="color:#333;" href="'.$path.'/'.$file[$i].'" target="_BLANK">'.substr($file[$i], 0, 70).'</a></td>'."\n";
			echo '   <td class="f_row_td3" align="left" valign="top" style="padding-top:1px;text-align:right;"><a class="f_file" style="color:#333;" href="'.$path.'/'.$file[$i].'" target="_BLANK">'.file_byte(filesize($path.'/'.$file[$i])).'</a></td>'."\n";
			echo '   <td class="f_row_td4" align="left" valign="top" style="padding-top:1px;text-align:right;"><a class="f_file" style="color:#333;" href="'.$path.'/'.$file[$i].'" target="_BLANK">'.date("d.m.Y H:i", filemtime($path.'/'.$file[$i])).'</a></td>'."\n";
			//echo '   <td class="f_row_td5" align="left" valign="middle" style="padding-top:1px;text-align:right;"><a class="f_icon" href="fmanager.php?a=freply&type=2&dir='.$dir.'&uri='.$path.$file[$i].'/" title="reply"><img src="fmanager/edit_rename.png" width="18" height="18" border="0" /></a></td>'."\n";
			echo '   <td class="f_row_td5" align="left" valign="middle" style="padding-top:1px;text-align:right;"><a class="f_icon" href="fmanager.php?a=rename&type=2&dir='.$dir.'&uri='.$path.'/'.$file[$i].'/" title="Cambiar nombre"><img src="fmanager/edit_rename.png" width="18" height="18" border="0" /></a></td>'."\n";	  

			echo '   <td class="f_row_td6" align="left" valign="middle" style="padding-top:1px;text-align:right;"><a class="f_icon" href="fmanager.php?exec=unlink&type=2&dir='.$dir.'&uri='.$path.'/'.$file[$i].'" title="Eliminar archivo"><img src="fmanager/edit_delete.png" width="16" height="16" border="0" /></a></td>'."\n";
			echo '</tr>'."\n";
		}
		closedir($dir_handle);
		echo '</table>'."\n";
	}
?>
</div></div></div>
</body>
</html>
